<!DOCTYPE html>
<HTML>
<HEAD><meta name="viewport" content="width=device-width, initial-scale=1">
<Title>Text Styles and Colors</Title>
<link type='text/css' rel='Stylesheet' href="maxchartapi.css" />
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">

<p class="heading0">ChartDirector 7.0 (Java Edition)</p>
<p class="heading1">Text Styles and Colors</p>
<hr class="separator">
<div class="content">
<img src="images/fontpie.jpg" width='480' height='300'>
<br><br>
This example demonstrates various text styles, text colors, background colors and text box border effects.<br><br>
In the chart above, 3 different pattern colors (wallpapers) are used for the chart background, legend box background and chart title background. In addition, the chart title, sector labels, and legends all have different fonts, text colors, background colors, and border styles.<br><br>
<ul><li> <a href="BaseChart.patternColor2.htm">BaseChart.patternColor2</a> is used to load the wallpaper images and return integers that represent the pattern colors created from the images.<br><br>
<li> The pattern colors are then used in <a href="BaseChart.setBackground.htm">BaseChart.setBackground</a>, and also the <a href="Box.setBackground.htm">Box.setBackground</a> methods of the <a href="LegendBox.htm">LegendBox</a> object and title <a href="TextBox.htm">TextBox</a> object to set the various background colors.<br><br>
<li> The title text and font are specified using <a href="BaseChart.addTitle.htm">BaseChart.addTitle</a>.<br><br>
<li> The legend box font is specified using <a href="BaseChart.addLegend.htm">BaseChart.addLegend</a>. It returns a <a href="LegendBox.htm">LegendBox</a> object to support further legend box configuration. In this example, the <a href="Box.setBackground.htm">Box.setBackground</a> method of this object is used to set the background color and 3D border effects of the legend box.<br><br>
<li> The default sector label font is specified using <a href="PieChart.setLabelStyle.htm">PieChart.setLabelStyle</a>.<br><br>
<li> The sector label font of individual sector is specified using <a href="Sector.setLabelStyle.htm">Sector.setLabelStyle</a>.<br><br>
<li> The sector label's background color, border color and 3D border effects are specified by first obtaining the <a href="TextBox.htm">TextBox</a> object that represents the sector label using <a href="Sector.setLabelStyle.htm">Sector.setLabelStyle</a>, then calling its <a href="Box.setBackground.htm">Box.setBackground</a> method.</ul>
</div>
<p class="heading1a">Source Code Listing</p>
<div class="content">
<b>[JSP Version]</b> jspdemo/fontpie.jsp
<div class='codeblock'><code class='pre'>&lt;%@page import="ChartDirector.*, java.util.*" %&gt;
&lt;%
// The data for the pie chart
double[] data = {25, 18, 15, 12, 8, 30, 35};

// The labels for the pie chart
String[] labels = {"Labor", "Licenses", "Taxes", "Legal", "Insurance", "Facilities", "Production"};

// Create a PieChart object of size 480 x 300 pixels
PieChart c = new PieChart(480, 300);

//Set search path to current JSP directory for loading icon images
c.setSearchPath(getServletConfig().getServletContext(), request);

// Use a blue marble pattern as the background wallpaper, with a black border, and 1 pixel 3D border
// effect
c.setBackground(c.patternColor("marble.png"), 0x000000, 1);

// Set the center of the pie at (150, 150) and the radius to 100 pixels
c.setPieSize(150, 150, 100);

// Add a title to the pie chart using Times Bold Italic/15 points/deep blue (0x000080) as font, with
// a wood pattern as the title background
c.addTitle("Project Cost Breakdown", "Times New Roman Bold Italic", 15, 0x000080).setBackground(
    c.patternColor("wood.png"));

// Draw the pie in 3D
c.set3D();

// Add a legend box using Arial Bold Italic/11 points font. Use a pink marble pattern as the
// background wallpaper, with a 1 pixel 3D border. The legend box is top-right aligned relative to
// the point (465, 70)
LegendBox b = c.addLegend(465, 70, true, "Arial Bold Italic", 11);
b.setBackground(c.patternColor("marble2.png"), Chart.Transparent, 1);
b.setAlignment(Chart.TopRight);

// Set the default font for all sector labels to Arial Bold/8pt/dark green (0x008000).
c.setLabelStyle("Arial Bold", 8, 0x008000);

// Set the pie data and the pie labels
c.setData(data, labels);

// Explode the 3rd sector
c.setExplode(2, 40);

// Use Arial Bold/12pt/red as label font for the 3rd sector
c.sector(2).setLabelStyle("Arial Bold", 12, 0xff0000);

// Use Arial/8pt/deep blue as label font for the 5th sector. Add a background box using the sector
// fill color (SameAsMainColor), with a black (0x000000) edge and 2 pixel 3D border.
c.sector(4).setLabelStyle("Arial", 8, 0x000080).setBackground(Chart.SameAsMainColor, 0x000000, 2);

// Use Arial Italic/8pt/light red (0xff9999) as label font for the 6th sector. Add a dark blue
// (0x000080) background box with a 2 pixel 3D border.
c.sector(0).setLabelStyle("Arial Italic", 8, 0xff9999).setBackground(0x000080, Chart.Transparent, 2)
    ;

// Use Times Bold Italic/8pt/deep green (0x008000) as label font for 7th sector. Add a yellow
// (0xFFFF00) background box with a black (0x000000) edge.
c.sector(6).setLabelStyle("Times New Roman Bold Italic", 8, 0x008000).setBackground(0xffff00,
    0x000000);

// Output the chart
WebChartViewer viewer = new WebChartViewer(request, "chart1");
viewer.setChart(c, Chart.SVG);

// Include tool tip for the chart
viewer.setImageMap(c.getHTMLImageMap("", "", "title='{label}: US${value}K ({percent}%)'"));
%&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Text Style and Colors&lt;/title&gt;
    &lt;!-- Include ChartDirector Javascript Library to support chart interactions --&gt;
    &lt;script type="text/javascript" src="cdjcv.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body style="margin:5px 0px 0px 5px"&gt;
    &lt;div style="font:bold 18pt verdana;"&gt;
        Text Style and Colors
    &lt;/div&gt;
    &lt;hr style="border:solid 1px #000080; background:#000080" /&gt;
    &lt;div style="font:10pt verdana; margin-bottom:1.5em"&gt;
        &lt;a href="viewsource.jsp?file=&lt;%=request.getServletPath()%&gt;"&gt;View Source Code&lt;/a&gt;
    &lt;/div&gt;
    &lt;!-- ****** Here is the chart image ****** --&gt;
    &lt;%= viewer.renderHTML(response) %&gt;
&lt;/body&gt;
&lt;/html&gt;</code></div>
</div>
<br><hr class="separator"><div class="copyright">&copy; 2022 Advanced Software Engineering Limited. All rights reserved.</div>
</body>
</HTML>
